<template>
  <!--  侧边栏-->
  <el-container>
    <el-aside width="200px">
      <el-scrollbar>
        <el-menu :default-openeds="['1', '4']">

<!--          管理员管理-->
          <el-sub-menu index="1" v-if="backendType==='super'">
            <template #title>
              <el-icon>
                <message />
              </el-icon>
              管理员
            </template>
            <el-menu-item-group>
              <el-menu-item index="1-1" @click="handleSuper('super')">超级管理员</el-menu-item>
              <el-menu-item index="1-2" @click="handleOrdinary('ordinary')">管理员</el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>


<!--          作者管理-->

          <el-menu-item index="2" @click="handleAuthor()">
            <el-icon>
              <message />
            </el-icon>
            作者管理
          </el-menu-item>

          <!--          用户管理-->

          <el-menu-item index="3" @click="handleUser()">
            <el-icon>
              <message />
            </el-icon>
            用户管理
          </el-menu-item>


<!--          小说管理-->
          <el-sub-menu index="4">
            <template #title>
              <el-icon>
                <setting />
              </el-icon>
              小说管理
            </template>
            <el-menu-item-group v-for="item in bookCategory" :key="item.id">
              <el-menu-item index="3-1" @click="handleBook(item.id)">{{ item.name }}</el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>
        </el-menu>
      </el-scrollbar>
    </el-aside>
  </el-container>
</template>

<script setup>
import {Message, Setting} from "@element-plus/icons-vue";
import {onMounted, ref} from "vue";
import {getBackendType} from "@/utils/auth";
import {getBookCategory} from "@/api/backend";
import {useRouter} from "vue-router";

const backendType = ref(getBackendType());
const router = useRouter()
onMounted(async () => {
const { data } = await getBookCategory();

// console.log(data);
bookCategory.value = data;
})

// 小说类别
const bookCategory = ref([]);

onMounted(() => {
  handleSuper("super")
})

const handleSuper = (type) => {
  router.push({
    path: `/backend/adminList/${type}`
  })
}

const handleOrdinary = (type) => {
  router.push({
    path: `/backend/adminList/${type}`
  })
}
const handleAuthor = () =>{
  router.push({
    path: '/backend/authorList'
  })
}
const handleUser = () => {
  router.push({
    path: '/backend/userList'
  })
}
const handleBook = (categoryId) => {
  router.push({
    path: `/backend/bookList/${categoryId}`
  })
}
</script>

<style scoped>

</style>